{% extends "center/base.html" %}
{% block title %}DSS平台{% endblock %}
{% block urlName %}list{% endblock %}
{% block section_name %}我的订阅计划{% endblock %}
{% block main %}
 <div class="ctbox goods">
                     <div class="tit">
                         <span class="r"><a class="btn sync fancybox" href="#data1">添加订阅计划</a></span>
                         <ul class="tab">
                            <li class="a">订阅列表</li>
                        </ul>

                     </div>

                     <div class="ctn">
  					<table width='100%' border='0'>
                         <tr>
		    <td width='15%' height='36' class='ltd' align='center' valign='middle'>编号</td>
		    <td width='70%'>名称</td>
		    <td width='15%' align='right' class='price'>操作</td>
		              </tr>
                            {% for line in item %}
                            <tr>
                                <td width='15%' height='38' align='center' valign='middle'>{{ line.id }}</td>
                                <td width='50%'>{{ line.task_name }}</td>
                                <td width='35%' align='right' class='price111' id='priceTag0'>
                                    <a href='edit?id={{ line.id }}'><img src='{% url static %}images/edit_btn.gif' /></a>
		      <a href='javascript:void(0)' onClick='delTask({{ line.id }})'><img src='{% url static %}images/delete_btn.gif' /></a>
                                    <a href='display/?id={{ line.id }}'><img src='{% url static %}images/preview_btn.gif'  /></a>
                                </td>
		                    </tr>
                            {% endfor %}
                            <tr>
                                <td colspan='3' class='pages'>
                                 {% if item.has_previous %}<a href="?page={{ page|add:-1 }}">上一页</a>{% endif %}
                                    &nbsp;&nbsp;&nbsp;{{ page|default:1 }}/&nbsp;{{ page_count }}&nbsp;&nbsp;
                                 {% if item.has_next %} <a href="?page={{ page|add:1 }}">下一页</a>{% endif %}
                                </td>
                            </tr>
                        </table>
                     </div>
  </div>

<div id="data1">
<div class="tit">添加订阅计划</div>
<form action="/doadd" method="POST" id="addfrm">
 <table width="100%" border="0" align="center" >
  <tr>
    <td width="100" height="45" align="right">计划名称:</td>
    <td width="180" align="center">
        <input type="text" name="task_name"  value="" />
    </td>
    <td><span id="task_name_msg"></span></td>
  </tr>
   <tr>
    <td width="100" height="45" align="right">店铺名称:</td>
    <td width="180" align="center">
        <input type="text" name="store_name"  value="" />
    </td>
    <td><span id="store_name_msg"></span></td>
  </tr>
  <tr>
    <td height="45" align="right">店铺地址:</td>
    <td align="center">
        <input type="text" name="store_url"  value="" />
    </td>
    <td><span id="store_url_msg"></span></td>
  </tr>
  <tr>
    <td height="45" align="right">状态:</td>
    <td align="center">
        <input type="radio" value="1" checked="checked" name="stat"/>启用
        <input type="radio" value="0"  name="stat"/>停用
    </td>
    <td></td>
  </tr>
  <tr>
    <td height="46" align="center"><input type="submit" value=" " id="submit" style="display: none;" /></td>
    <td height="46" align="center"><span class="r"><a class="btn sync" href="#" id="click_submit">确定</a></span></td>
    <td height="46" align="center">&nbsp;</td>
  </tr>
</table>
</form>
</div>
{% endblock %}
{% block readyfunction %}
  $("#click_submit").click(function (){
        $("#submit").trigger("click");
  });

$("a.fancybox").fancybox();
    $('#addfrm').ajaxForm({
		//target: '#output_result',
		dataType: 'json',
		beforeSubmit: function (formData, jqForm, options){
			var _el = null;
			for(var i=0; i<formData.length; i++){
				_el = formData[i];
				if(_el.name == 'task_name'){
					if(_el.value.length < 1){
						$('#task_name_msg').html('计划名称不能为空！');
						return false;
					}
				}
				else if(_el.name == 'store_url'){
					if(_el.value.length < 1){
						$('#store_url_msg').html('店铺地址不能为空！');
						return false;
					}
				}

                else if(_el.name == 'store_name'){
					if(_el.value.length < 1){
						$('#store_name_msg').html('店铺名称不能为空！');
						return false;
					}
				}
				else if(_el.name == 'stat'){
					if(_el.value.length < 1){
						//$('#validateCode_result').html('验证码必须为4位！');
						return false;
					}
				}
			}
			return true;
		},
		success: function (data){

                alert(data.msg);
                location.reload() ;

		}
	});
{% endblock %}
{% block headarea %}
    <script type="text/javascript" src="http://agent.happy001.com/js/jquery.form.js"></script>
    <style>
     #priceTag0 a{float: left;padding-left: 1px;}
    </style>
    <script>
    function delTask(id){
        if (id<1) return false;
        $.ajax({
				type: "POST",
				url: "{% url delTask %}",
				data: {id:id},
				dataType: 'json',
				success: function(rs){
					alert(rs.msg);
                    if(rs.status=='ok'){
                         location.reload() ;
                    }
				}
			});

    }
    </script>
{% endblock %}